﻿<div id="main">
    <div id="contents">
            <fieldset>
                <legend>
                    <label sid="ivr.table1_td7" id="title_1"></label>
                    <script type="text/javascript">
                        document.getElementById("title_1").innerHTML=ivr.table1_td7;
                    </script>
                </legend>
                <div class="frame_tab_layer">
                    <table class="cmenutitle" cellspacing="0" cellpadding="0" border="0" width="100%">
                        <tbody>
                        <tr>
                            <td class="frame_tab_right">
                                <select id="id748" style="width:150px;" name="id748"></select>
                                <span style="padding-left:15px;">&nbsp;</span>
                                <a id="download_id748" name="download" href="#">
                                    <img border="0" src="images/listen.gif">
                                </a>
                                <span style="padding-left:15px;">&nbsp;</span>
                                <input class="button" type="button" name="submit" sid="sbutton.ok" value="确 认"/>
                              <!--  <button class="button" name="submit" id="ok_button">
                                    <script type="text/javascript">
                                        document.getElementById("ok_button").innerHTML=sbutton.ok;
                                    </script>
                                </button>-->
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </fieldset>
            <fieldset>
                <legend>
                    <label sid="ivr.table1_td8" id="title_2" ></label>
                    <script type="text/javascript">
                        document.getElementById("title_2").innerHTML=ivr.table1_td8;
                    </script>
                </legend>
                <div class="frame_tab_layer">
<span id="loading" style="display:none;">
<label sid="cfgupload.cprogress"></label>
</span>
                    <table class="cmenutitle" cellspacing="0" cellpadding="0" border="0" width="100%">
                        <tbody>
                        <tr>
                            <td class="frame_tab_right">
                                <input id="filename" type="file" size="35" name="filename">
                                <input class="button" type="button" name="upload" sid="sbutton.upload" value="上 传"/>


                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </fieldset>
            <fieldset>
                <legend>
                    <label sid="ivr.table1_td9" id="title_3"></label>
                  <script type="text/javascript">
                      document.getElementById("title_3").innerHTML=ivr.table1_td9;
                  </script>
                </legend>
                <div class="frame_tab_layer">
                    <table class="cmenutitle" cellspacing="0" cellpadding="0" border="0" width="100%">
                        <tbody>
                        <tr>
                            <td class="frame_tab_right">
                                <select id="ivr" style="width:150px;" name="ivr"></select>
                                <span style="padding-left:15px;">&nbsp;</span>
                                <a id="download_ivr" name="download" href="#">
                                    <img border="0" src="images/listen.gif">
                                </a>
                                <span style="padding-left:15px;">&nbsp;</span>
                                <input class="button" type="button" name="delete" sid="sbutton.del" value="删 除"/>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </fieldset>
            <fieldset>
                <legend>
                  <label sid="operator.table2_tts" id="title_4"></label>
                 <script type="text/javascript">
                     document.getElementById("title_4").innerHTML=operator.table2_tts;
                 </script>
                </legend>
                <div class="frame_tab_layer">
                    <table class="cmenutitle" cellspacing="0" cellpadding="0" border="0" width="100%">
                        <tbody>
                        <tr>
                            <td class="frame_tab_right">
                                <input id="go_url_tts" class="button" type="button" name="tts" sid="operator.table2_tts" value="文字转欢迎词">
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </fieldset>
    </div>
</div>
<br>
<div id="helpContainer">
    <div id="help">
        <div>
            <h2>
                <label sid="share.help"></label>
            </h2>
        </div>
        <div id="helpBody">
        <dl>
            <dt class="term">
                <label sid="ivr.table2_title"></label>
            </dt>
            <dd class="definition">
                <label sid="ivr.table2_title_note"></label>
            </dd>
        </dl>
        </div>
    </div>
</div>
<script type="text/javascript" src="js/ajaxfileupload.js"></script>
<script type="text/javascript">
function startupgrade() {
    report=function (message) {
        $.ajaxFileUpload({
            url:'upgrade',data:'upgrade=upgrade',dataType:'xml',error:function (data,status,e) {
                $("[name=submit]").attr("disabled",false);
                $("[name=delete]").attr("disabled",false);
                $(data).find('Error').each(function () {
                    var errortext=$(this).attr('msg');
                    alert(errortext);
                });
            },success:function (data,status) {
                var stat=$(data).find("rsp").attr("stat");
                if(stat=="ok") {
                    $("#loading").hide();
                    clearInterval(timer);
                    $("[name=submit]").attr("disabled",false);
                    $("[name=delete]").attr("disabled",false);
                    //show_message("success",cfgupload.upok);
                    alert(cfgupload.upok);
                    window.location.reload();
                }else if(stat=="inprogress") {
                    $("#loading").show();
                }else {
                    $("#loading").hide();
                    clearInterval(timer);
                    $("[name=submit]").attr("disabled",false);
                    $("[name=delete]").attr("disabled",false);
                    var error=$(data).find("error").text();
                    //show_message("err",cfgupload.upfail);
                    alert(cfgupload.upfail);
                }
            }
        });
    }
    timer=setInterval(report,5000);
}

function checkivr() {
    var wrongType=msg.wrongType;
    var noFile=msg.noFile;
    var length=$("#filename").val().length;
    var filetype=$("#filename").val().substring(length-3);
    var files=$("#filename").val().split("\\");
    var lengthss=files.length;
    var filename=files[lengthss-1];
    if($("#filename").val()!=="") {
        if((filetype=="dat"||filetype=="pcm")&&(filename.split(".")[0].substr(0,4)=="user")) {
            return true;
        }else {
            //show_message("err",wrongType);
            alert(wrongType);
        }
    }else {
        //show_message("err",noFile);
        alert(noFile);
    }
    return false;
}

function startupload() {
    if(checkivr()) {
        $("[name=submit]").attr("disabled",true);
        $("[name=delete]").attr("disabled",true);
        $("#loading").show();
        $.ajaxFileUpload({
            url:'upload',secureuri:false,fileElementId:'filename',dataType:'xml',success:function (data,status) {
                var stat=$(data).find("rsp").attr("stat");
                if(stat=="ok") {
                    startupgrade();
                }else if(stat=="fail") {
                    $("#loading").hide();
                    $("[name=submit]").attr("disabled",false);
                    $("[name=delete]").attr("disabled",false);
                    var error=$(data).find("error").text();
                    //show_message("err",cfgupload.error);
                    alert(cfgupload.error);
                }
            },error:function (data,status,e) {
                $("#loading").hide();
                $("[name=submit]").attr("disabled",false);
                $("[name=delete]").attr("disabled",false);
                //show_message("err",cfgupload.upfail);
                alert(cfgupload.upfail);
            }
        });
    }
}


window.onbeforeunload=function () {
    $.ajax({
        type:"POST",url:'cancelupgrade',data:'cancelupgrade=cancelupgrade',dataType:'xml',error:function (xml) {
            $(xml).find('Error').each(function () {
                var errortext=$(this).attr('msg');
                alert(errortext);
            });
        }
    });
}
var cannotModify=msg.cannotModify1;
var ifDelete=msg.confirm_del;
$("#download_id748").click(function () {
    var thisivr=$("[name=id748]").val();
    if(thisivr!="") {
        thisivr=thisivr.split(".")[0];
        $.ajax({
            type:"POST",url:'xml',data:'method=gw.command.set&action=download&file='+thisivr+'&tmp='+Math.random(),dataType:"xml",error:function (xml) {
                $(xml).find('Error').each(function () {
                    var errortext=$(this).attr('msg');
                    alert(errortext);
                });
            },success:function (xml) {
                var rspstat=$(xml).find("rsp").attr("stat");
                if(rspstat=="ok") {
                    var file=thisivr+".wav";
                    window.top.location.href=file;
                    $("#result").html("");
                }
            }
        });
    }else {
        //show_message("err",ivr.cue1);
        alert(ivr.cue1);
    }
});
$("#download_ivr").click(function () {
    var thisivr=$("[name=ivr]").val();
    if(thisivr!="") {
        $.ajax({
            type:"POST",url:'xml',data:'method=gw.command.set&action=download&file='+thisivr+'&tmp='+Math.random(),dataType:"xml",error:function (xml) {
                $(xml).find('Error').each(function () {
                    var errortext=$(this).attr('msg');
                    alert(errortext);
                });
            },success:function (xml) {
                var rspstat=$(xml).find("rsp").attr("stat");
                if(rspstat=="ok") {
                    var file=thisivr+".wav";
                    window.top.location.href=file;
                    $("#result").html("");
                }
            }
        });
    }else {
        //show_message("err",ivr.cue1);
        alert(ivr.cue1);
    }
});
$("[name=delete]").click(function () {
    if(confirm(ifDelete)) {
        var deleteivr=$("#ivr").val().split(".")[0];
        var settext="&id771="+deleteivr;
        settext=settext.replace(/\#/g,"%23");
        submitform(modules["set_data"],settext);
        loadNewHtml("ivr_main_load.htm");
        return true;
    }else {
        return false;
    }
});
var url='/xml?method=gw.config.get&id=771&&tmp='+Math.random();
$.get(url,function (data) {
    var stat=$(data).find('rsp').attr("value");
    if(stat=="fail") {
        $(data).find('Error').each(function () {
            var code=$(this).attr('code');
            if(code==4) {
                //show_message("err",cannotModify);
                alert(cannotModify);
            }else if(code==5) {
                gotologin();
            }
        });
    }else {
        var optionstr='';
        var deleteivr='<option value="">--</option>';
        var linehtml='';
        var ivrarray=new Array();
        var ivr748=new Array();
        var m=0;
        var n=0;
        $(data).find('item').each(function () {
            if($(this).attr("id")=="771") {
                var ivrs=$(this).attr("value").split("|");
                for(var i=0;i<ivrs.length;i++) {
                    if(ivrs[i].indexOf("user")>=0) {
                        ivrarray[m]=ivrs[i].split(".")[0];
                        m++;
                        ivr748[n]=ivrs[i].split(".")[0];
                        n++;
                    }else if((ivrs[i].indexOf("welcome")>=0&&ivrs[i].split(".")[0]!=="welcome")||(ivrs[i].indexOf("offhour")>=0&&ivrs[i].split(".")[0]!=="offhour")) {
                        ivrarray[m]=ivrs[i].split(".")[0];
                        m++;
                    }else if(ivrs[i].indexOf("NewMorning")>=0||ivrs[i].indexOf("fring")>=0) {
                        ivr748[n]=ivrs[i].split(".")[0];
                        n++;
                    }
                }
            }
        });
        ivrarray=unique(ivrarray);
        ivr748=unique(ivr748);
        for(var n=0;n<ivrarray.length;n++) {
            deleteivr+='<option>'+ivrarray[n]+'</option>';
        }for(var m=0;m<ivr748.length;m++) {
            optionstr+='<option>'+ivr748[m]+'</option>';
        }$("#ivr").html(deleteivr);
        $("select[name=id748]").html(optionstr);
        var gettext='&id=748';
        var nonames=new Array('call','test','submit','filename','upload','reset','filename','checkline',"ivr","delete","tts");
        sendinfo(gettext,nonames);
    }
});
$("[name=submit]").click(function () {
    $(".errormsg").html('');
    var settext='&id748='+$("[name=id748]").val();
    submitform(modules["set_data"],settext);
});
$("[name=upload]").click(function () {
    startupload();
});
$("#go_url_tts").bind("click",function(){
    $("#tts_main_load").click();
});
</script>
